/*
package com.jymj.controller;

import com.jymj.entity.zjd.ApplyChildFileEty;
import com.jymj.service.ApplyChildFileService;
import com.jymj.utils.R;
import com.jymj.utils.TimeString;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

*/
/**
 * Created by ljj on 2018/9/12.
 *//*

@RestController
@RequestMapping("/applyChildFile")
public class ApplyChildFileController extends AbstractController {
    @Autowired
    private ApplyChildFileService applyChildFileService;
    private final String SAVE_DIR = "applyChildFile";

    @RequestMapping(value = "/upload" ,method = RequestMethod.POST )
    @ResponseBody
    public Map upload(HttpServletRequest request, HttpServletResponse response) throws FileNotFoundException {
        Map<String, Object> map = new HashMap();
        //资料表实体
        ApplyChildFileEty applyChildFileEntity = new ApplyChildFileEty();
        // 获取根目录的绝对路径
        File genPath=new File(ResourceUtils.getURL("classpath:").getPath());
        if(!genPath.exists()){
            genPath=new File("");
        }
        //在开发测试模式时，得到地址为：{项目跟目录}/target/progress/
        //在打成jar正式发布时，得到的地址为:{发布jar包目录}/progress/
        File savePath=new File(genPath.getAbsolutePath(),"fileupload"+ File.separator+SAVE_DIR);
        File savePath1=new File(genPath.getAbsolutePath(),"fileupload");
        if(!savePath.exists()){
            savePath.mkdirs();
            System.out.println("文件路径为：+"+savePath.getAbsolutePath());
        }
        //if (multipartResolver.isMultipart(request)) {
        //转换成多部分request
        MultipartHttpServletRequest multiRequest =null;
        if (request instanceof MultipartHttpServletRequest) {
            multiRequest = (MultipartHttpServletRequest)(request);
        }else {
            return R.error("文件不能为空！");
        }
        //取得request中的所有文件名
        Iterator<String> iter = multiRequest.getFileNames();
        while (iter.hasNext()) {
            //取得上传文件
            MultipartFile file = multiRequest.getFile(iter.next());
            if (file != null) {
                //取得当前上传文件的文件名称
                String myFileName = file.getOriginalFilename();
                //如果名称不为“”,说明该文件存在，否则说明该文件不存在
                if (!"".equals(myFileName.trim())) {
                    //重命名上传后的文件名
                    String fileName = file.getOriginalFilename();
                    //System.out.println(savePath + "\\" + fileName);
                    applyChildFileEntity.setFilename(fileName);
                    String ext = fileName.substring(fileName.indexOf("."));
                    TimeString st = new TimeString();
                    applyChildFileEntity.setFileurl(SAVE_DIR+ File.separator+st.getTimeString() + ext);
                    applyChildFileEntity.setUpdate(new Date());
                    applyChildFileService.save(applyChildFileEntity);
                    //上传路径
                    String path = savePath1 + File.separator + applyChildFileEntity.getFileurl();
                    File localFile = new File(path);
                    try {
                        file.transferTo(localFile);
                    } catch (IOException e) {
                        return R.error("上传失败").put("code", 500);
                    }
                }
            } else {
                return R.error("文件不能为空！");
            }
        }
        //}
        map.put("data", applyChildFileEntity);
        map.put("msg", "上传成功！");
        map.put("code", 0);
        return map;
    }

    private ApplyChildFileEty getApplyChildFile(MultipartHttpServletRequest multiRequest) {
        ApplyChildFileEty applyChildFileEntity = new ApplyChildFileEty();
        String appid = multiRequest.getParameter("appid");
        if(appid!=null && !appid.equals("")){
            applyChildFileEntity.setAppid(Integer.parseInt(appid));
        }
        String sgtype = multiRequest.getParameter("sgtype");
        if(sgtype!=null && !sgtype.equals("")){
            applyChildFileEntity.setSgtype(Integer.parseInt(sgtype));
        }
        String filetype = multiRequest.getParameter("filetype");
        if(filetype!=null && !filetype.equals("")){
            applyChildFileEntity.setFiletype(Integer.parseInt(filetype));
        }
        return applyChildFileEntity;
    }

    */
/**
     * 删除
     *//*

    @RequestMapping("/delete")
    @ResponseBody
    public R delete(@RequestBody Map map, HttpServletRequest request) throws FileNotFoundException {
        File genPath=new File(ResourceUtils.getURL("jar:").getPath());
        File savePath=new File(genPath.getAbsolutePath().replace("jar:","fileupload"));
        Integer id = null;
        if (map.containsKey("id")){
            id = Integer.valueOf(map.get("id").toString());
        }
        if(id==null){
            return R.ok();
        }
        ApplyChildFileEty applyChildFileEty = applyChildFileService.queryObject(id);
        if(applyChildFileEty.getSgtype()!=null && applyChildFileEty.getSgtype()!=74){
            String path = savePath + File.separator  + applyChildFileEty.getFileurl();
            File files = new File(path);
            files.delete();
        }
         ids = new Integer[5];
        ids[0]=id;
        applyChildFileService.deleteBatch(ids);
        return R.ok();
    }

}
*/
